package com.marvels.approve.manager.controller;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fintech.third.model.interfacedata.EdcInterfaceCodeInfoDto;
import com.fintech.third.service.interfacedata.InterfaceCodeInfoService;
import com.marvels.approve.consum.ApproveConsumerLoanApplyApi;
import com.marvels.common.utils.MarvelsLogUtil;

@RestController
@RequestMapping("approve/external/bill")
public class ApproveCheckBillController {

	@Autowired
	private InterfaceCodeInfoService interfaceCodeInfoService;
	@Autowired
	private ApproveConsumerLoanApplyApi consumerLoanApplyApi;
	
/*	
	@RequestMapping("paymentBill")
	@ResponseBody
	public Map<String,Object> paymentBill(@RequestBody java.util.LinkedHashMap map){
		String startDate =  (String)map.get("startDate");
		if(StringUtils.isNotBlank(startDate)){
			startDate = startDate.substring(0, 10);
			map.put("startDate", startDate);
		}
		String endDate = (String)map.get("endDate");
		if(StringUtils.isNotBlank(endDate)){
			endDate = endDate.substring(0, 10);
			map.put("endDate", endDate);
		}
		Map<String,Object> pageInfo = interfaceCodeInfoService.selectInterfacePaymentBill(map);
		List list = (List)pageInfo.get("items");
//		List list = page.getResult();
		String userMobiles = "";
		for (int i = 0; i < list.size(); i++) {
			Map mapData = (Map<String,Object>)list.get(i);
			String mobile = (String)mapData.get("createdByMobile");
			if (StringUtils.isNotBlank(mobile)) {
				userMobiles+=mobile+",";
			}
		}
		if (StringUtils.isNotBlank(userMobiles)) {
			userMobiles = userMobiles.substring(0,userMobiles.length()-1);			
			Map<String,String> names = consumerLoanApplyApi.queryUserNameBymobiles(userMobiles);
			for (int i = 0; i < list.size(); i++) {
				Map mapData = (Map<String,Object>)list.get(i);
				mapData.put("createdBy", names.get(mapData.get("createdByMobile")));
			}
		}
		return pageInfo;
	}
	*/
	/*@RequestMapping("paymentBillAmount")
	@ResponseBody
	public Double paymentBillAmount(@RequestBody java.util.LinkedHashMap map){
		MarvelsLogUtil.getInstance().info(">>>>>>>>>dubbo 获取支付账单总金额 paymentBillAmount controller入参:"+JSONObject.fromObject(map));
		String startDate =  (String)map.get("startDate");
		if(StringUtils.isNotBlank(startDate)){
			startDate = startDate.substring(0, 10);
			map.put("startDate", startDate);
		}
		String endDate = (String)map.get("endDate");
		if(StringUtils.isNotBlank(endDate)){
			endDate = endDate.substring(0, 10);
			map.put("endDate", endDate);
		}
		
		//		Map<String, Object> data = interfaceCodeInfoService.selectInterfacePaymentBill(map);
		Double amount = interfaceCodeInfoService.countInterfacePaymentBill(map);
		return amount;
	}*/
	
	
	@RequestMapping("feeTypeList")
	@ResponseBody
	public List<EdcInterfaceCodeInfoDto> feeTypeList(){
		MarvelsLogUtil.getInstance().info(">>>>>>>>>dubbo获取收费类型列表 feeTypeList controller----:");
		List<EdcInterfaceCodeInfoDto> list =interfaceCodeInfoService.selectInterfaceConfigType();
		return list;
	}
	
	
	@RequestMapping("everydayPaymentBill")
	@ResponseBody
	public Map<String,Object> everydayPaymentBill(@RequestBody java.util.LinkedHashMap map){
		Map<String,Object> pageInfo = interfaceCodeInfoService.selectInterfacePaymentBill2(map);
		return pageInfo;
	}
	
	@RequestMapping("paymentBill")
	@ResponseBody
	public Map<String,Object> paymentBill(@RequestBody java.util.LinkedHashMap map){
		String createdBy = (String) map.get("createdBy");// 统计人姓名
		String mobileArray = consumerLoanApplyApi.selectUserIdByName(createdBy);
		map.put("createdBy", mobileArray);
		Map<String,Object> pageInfo = interfaceCodeInfoService.selectInterfacePaymentBill(map);
		List list = (List)pageInfo.get("items");
//		List list = page.getResult();
		String userMobiles = "";
		for (int i = 0; i < list.size(); i++) {
			Map mapData = (Map<String,Object>)list.get(i);
			String mobile = (String)mapData.get("createdByMobile");
			if (StringUtils.isNotBlank(mobile)) {
				userMobiles+=mobile+",";
			}
		}
		if (StringUtils.isNotBlank(userMobiles)) {
			userMobiles = userMobiles.substring(0,userMobiles.length()-1);			
			Map<String,String> names = consumerLoanApplyApi.queryUserNameBymobiles(userMobiles);
			for (int i = 0; i < list.size(); i++) {
				Map mapData = (Map<String,Object>)list.get(i);
				mapData.put("createdBy", names.get(mapData.get("createdByMobile")));
			}
		}
		return pageInfo;
	}
}
